try{XN = {}}catch(ex){XN={}};

//FWK 常用函数
FWK.extend(XN,{
	doMain:FWK.getDomain(),
	/**
	 * 检测 _xml 是否是符合正确返回
	 * @param {XML} _xml
	 * @return 正确：true
	 * @return 错误：{code:代码,des:原因}
	 */
	checkResponse : function(_xml){
		if(_xml){
			xml = _xml.documentElement || _xml;
			if(!xml.getAttribute("error") || xml.getAttribute("error")=="0"){
				return true;
			}
			else{
				var mess = xml.selectSingleNode("./*");
				var code = mess.getAttribute("code");
				if(mess){
					return {code:code, des:mess.getAttribute("des") || "未知错误，请稍后再试..."}
				}
				else{
					return {code:"",des:""}
				}
			}
		}
		else{
			return {code:-1,des:"连接服务器失败"}
		}
	},
	/**
	 * 获取地址栏中传入的数据
	 * @param {String | Array} _sName
	 * @return {String | Array}_sName 对应的值
	 */
	getQuery : function(_sName){
		if(FWK.isStr(_sName)){
			var sRE = "[?& ]+" + _sName + "=([^(&)]*)[&]?";
			var oRE = new RegExp(sRE);
			if(oRE.test(document.location.search)){
				return decodeURIComponent(RegExp["$1"]);
			}
			else{
				return null;
			}
		}
		else if(FWK.isArr(_sName)){
			var reArr = [];
			for(var i=0,ilen=_sName.lenght;i<ilen;i+=1){
				var sRE = "[?& ]+" + _sName[i] + "=([^(&)]*)[&]?";
				var oRE = new RegExp(sRE);
				if(oRE.test(document.location.search)){
					reArr.push(decodeURIComponent(RegExp["$1"]));
				}
				else{
					reArr.push(null);
				}
			}
			return reArr;
		}
	},
	/**
	 * 获取 cookie中特定值
	 * @param {Object} _sName
	 */
	getCookieQuery:function(_sName){
		if(FWK.isStr(_sName)){
			var sRE = "(?:; )?"+_sName+"=([^;]*);?";
	        var oRE = new RegExp(sRE);
	        if (oRE.test(document.cookie)) {
	            return decodeURIComponent(RegExp["$1"]);
	        } else {
	            return null;
	        }
		}
		else if(FWK.isArr(_sName)){
			var reArr = [];
			for(var i=0,ilen=_sName.lenght;i<ilen;i+=1){
				var sRE = "(?:; )?"+_sName[i]+"=([^;]*);?";
		        var oRE = new RegExp(sRE);
		        if (oRE.test(document.cookie)) {
		            reArr.push(decodeURIComponent(RegExp["$1"]));
		        } else {
		            reArr.push(null);
		        }
			}
			return reArr;
		}
	},
	/**
	 * 将 _htmlStr 字符串中的 /\{\#([\w\$\.]+)\}/g 替换成 _obj.$1 对应的值
	 * @param {String} _htmlStr
	 * @param {Object} _obj
	 */
	htmlFormat : function(_htmlStr,_obj){
		return _htmlStr.replace(/\{\#([\w\$\.]+)\}/g,function($0,$1){
			var rv = eval("_obj." + $1);
			if(!rv) {
				rv = "";
			}
			return rv;
		});
	},
	/**
	 * Id 转换地址函数
	 * @param {Number} _num			资源编号
	 * @param {Number} _dimension	资源深度		默认4
	 * @param {Number} _step		每层多少资源 默认1000
	 */
	toPath : function(_num,_dimension,_step){
		var infoStr = "";
		_step = (FWK.isNum(_step))?_step:1000;
		_dimension = (FWK.isNum(_dimension))?_dimension:4;
		var gene = 1;
		for (var i = 1; i < _dimension; i++){
			gene *= _step;
		}

		var  tempUserID = parseInt(_num);
		for (var i = 0; i < _dimension; i++) {
			if(_dimension != i + 1){
				var  temp = Math.floor(tempUserID / gene);
				tempUserID = tempUserID % gene;
				infoStr += "/" + temp;
				gene /= _step;
			}
			else{
				infoStr += "/" + _num;
			}
		}
		return infoStr;
	},
	toText:function(text){
		text = text.replace(/</g,"&lt;");
		text = text.replace(/>/g,"&gt;");
		text = text.replace(/\n/g,"<br />");
		return text;
	},
	/**
	 * 将 iterable 转成数组
	 * @param {Object} _iterable
	 */
	toArray : function (_iterable) {
		if(!_iterable) {
			return [];
		}
		if(_iterable.toArray) {
			return _iterable.toArray();
		}
		var results = [];
		for (var i = 0; i < _iterable.length; i++) {
			results.push(_iterable[i]);
		}
		return results;
	}
});